//热卖tab
function tabApi(type,spanIndex){
    $.get("http://kg.zhaodashen.cn/v1/goods/index.jsp",{type},res=>{
        let html=""
        $.each(res.data.list,(index,item)=>{
            html+=`
                    <li>
                        <dl>
                            <dt><a href="./goods.html?gid=${item.goods_id}"><img src="http://tmp00001.zhaodashen.cn/${item.goods_img}" alt="" /></a></dt>
                            <dd><a href="./goods.html?gid=${item.goods_id}">${item.goods_name}</a></dd>
                            <dd><span>售价：</span><strong> ￥${item.goods_name}</strong></dd>
                        </dl>
                    </li>
                `
        })
        $(`.guide_wrap div:eq(${spanIndex}) ul`).html(html)
    },"json")
}


$(function(){
    //商品分类
    // $.get("http://kg.zhaodashen.cn/v1/category/index.jsp",{},res=>{
    //     $(".cat_bd").css("overflow","hiden")
    //     let html=""
    //     $.each(res.data,(index,item)=>{
    //         if(index>12)return
    //         html+=`<div class="cat item1">`
    //             html+=`<h3><a href="${item.url || './list.html?keywords='+item.keywords}">${item.cat_name}</a> <b></b></h3>`
    //             html+=`<div class="cat_detail">`
    //             $.each(item.children,(index,item)=>{
    //                 html+=`<dl class="dl_1st">`
    //                     html+=`<dt><a href="${item.url || './list.html?keywords='+item.keywords}">${item.cat_name}</a></dt>`
    //                     html+=`<dd>`
    //                         $.each(item.children,(index,item)=>{
    //                             html+=`<a href="${item.url || './list.html?cat='+item.cat_id}">${item.cat_name}</a>`	
    //                         })
                            		
    //                     html+=`</dd>`
    //                 html+=`</dl>`
    //             })
                    
    //             html+=`</div>`
    //         html+=`</div>`
                
    //     })
    //     $(".cat_bd").html(html)
    // },"json")
    


    //热卖tab
    //首次
    tabApi("hot",0)
    //后续
    $(".guide_content h2 span").mouseover(function(){
        let spanIndex=$(this).index()
        let title=$(this).text()
        let titleEnglish={"热卖商品":"hot","推荐商品":"best","新品上架":"new",}
        //调用上面封装的
        tabApi(titleEnglish[title],spanIndex)
    })

    //猜你喜欢
    $.get("http://kg.zhaodashen.cn/v1/goods/like.jsp",{},res=>{
        // console.log(res);
        let html=""
        $.each(res.data,(index,item)=>{
            html+=`
                <li>
					<dl>
						<dt><a href="./goods.html?gid=${item.goods_id}"><img src="http://tmp00001.zhaodashen.cn/${item.goods_img}" alt="" /></a></dt>
						<dd><a href="./goods.html?gid=${item.goods_id}">${item.goods_name}</a></dd>
						<dd><span>售价：</span> <strong>￥${item.goods_name}</strong></dd>
					</dl>
				</li>
            `
        })
        $(".goodslist ul").html(html)
    },"json")
})